﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using PBDesk.FeedService.ServiceContracts;
using System.ServiceModel.Syndication;
using System.ServiceModel.Web;
using System.ServiceModel.Activation;

namespace PBDesk.FeedService.Services
{
    [AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]
    public class PBDeskFeed : IPBDeskFeed
    {        
        public System.ServiceModel.Syndication.SyndicationFeedFormatter PBDeskComFeeds()
        {
            // Create a new Syndication Feed.
            SyndicationFeed feed = new SyndicationFeed("Feed Title - f1", "A WCF Syndication Feed for f1", null);
            List<SyndicationItem> items = new List<SyndicationItem>();

            // Create a new Syndication Item.
            SyndicationItem item = new SyndicationItem("An item for f1", "Item content f1", null);
            items.Add(item);
            feed.Items = items;

            // Return ATOM or RSS based on query string
            // rss -> http://localhost:8732/Design_Time_Addresses/PBDesk.FeedService/Feed1/
            // atom -> http://localhost:8732/Design_Time_Addresses/PBDesk.FeedService/Feed1/?format=atom
            string query = WebOperationContext.Current.IncomingRequest.UriTemplateMatch.QueryParameters["format"];
            SyndicationFeedFormatter formatter = null;
            if (query == "atom")
            {
                formatter = new Atom10FeedFormatter(feed);
            }
            else
            {
                formatter = new Rss20FeedFormatter(feed);
            }

            return formatter;
        }

        public System.ServiceModel.Syndication.SyndicationFeedFormatter TechNews()
        {
            // Create a new Syndication Feed.
            SyndicationFeed feed = new SyndicationFeed("Feed Title - f2", "A WCF Syndication Feed for f2", null);
            List<SyndicationItem> items = new List<SyndicationItem>();

            // Create a new Syndication Item.
            SyndicationItem item = new SyndicationItem("An item for f2", "Item content f2", null);
            items.Add(item);
            feed.Items = items;

            // Return ATOM or RSS based on query string
            // rss -> http://localhost:8732/Design_Time_Addresses/PBDesk.FeedService/Feed1/
            // atom -> http://localhost:8732/Design_Time_Addresses/PBDesk.FeedService/Feed1/?format=atom
            string query = WebOperationContext.Current.IncomingRequest.UriTemplateMatch.QueryParameters["format"];
            SyndicationFeedFormatter formatter = null;
            if (query == "atom")
            {
                formatter = new Atom10FeedFormatter(feed);
            }
            else
            {
                formatter = new Rss20FeedFormatter(feed);
            }

            return formatter;
        }

        public System.ServiceModel.Syndication.SyndicationFeedFormatter CSharpNews()
        {
            // Create a new Syndication Feed.
            SyndicationFeed feed = new SyndicationFeed("Feed Title - f3", "A WCF Syndication Feed for f3", null);
            List<SyndicationItem> items = new List<SyndicationItem>();

            // Create a new Syndication Item.
            SyndicationItem item = new SyndicationItem("An item for f3", "Item content f3", null);
            items.Add(item);
            feed.Items = items;

            // Return ATOM or RSS based on query string
            // rss -> http://localhost:8732/Design_Time_Addresses/PBDesk.FeedService/Feed1/
            // atom -> http://localhost:8732/Design_Time_Addresses/PBDesk.FeedService/Feed1/?format=atom
            string query = WebOperationContext.Current.IncomingRequest.UriTemplateMatch.QueryParameters["format"];
            SyndicationFeedFormatter formatter = null;
            if (query == "atom")
            {
                formatter = new Atom10FeedFormatter(feed);
            }
            else
            {
                formatter = new Rss20FeedFormatter(feed);
            }

            return formatter;
        }

        public System.ServiceModel.Syndication.SyndicationFeedFormatter FeaturedArticles()
        {
            // Create a new Syndication Feed.
            SyndicationFeed feed = new SyndicationFeed("Feed Title - f4", "A WCF Syndication Feed for f4", null);
            List<SyndicationItem> items = new List<SyndicationItem>();

            // Create a new Syndication Item.
            SyndicationItem item = new SyndicationItem("An item for f4", "Item content f4", null);
            items.Add(item);
            feed.Items = items;

            // Return ATOM or RSS based on query string
            // rss -> http://localhost:8732/Design_Time_Addresses/PBDesk.FeedService/Feed1/
            // atom -> http://localhost:8732/Design_Time_Addresses/PBDesk.FeedService/Feed1/?format=atom
            string query = WebOperationContext.Current.IncomingRequest.UriTemplateMatch.QueryParameters["format"];
            SyndicationFeedFormatter formatter = null;
            if (query == "atom")
            {
                formatter = new Atom10FeedFormatter(feed);
            }
            else
            {
                formatter = new Rss20FeedFormatter(feed);
            }

            return formatter;
        }


        public SyndicationFeedFormatter CSharp_Articles()
        {
            // Create a new Syndication Feed.
            SyndicationFeed feed = new SyndicationFeed("C# Articles", "A WCF Syndication Feed for C# Articles", null);
            List<SyndicationItem> items = new List<SyndicationItem>();

            // Create a new Syndication Item.
            SyndicationItem item = new SyndicationItem("An item for C# Articles", "Item content C# Articles", null);
            items.Add(item);
            feed.Items = items;

            // Return ATOM or RSS based on query string
            // rss -> http://localhost:8732/Design_Time_Addresses/PBDesk.FeedService/Feed1/
            // atom -> http://localhost:8732/Design_Time_Addresses/PBDesk.FeedService/Feed1/?format=atom
            string query = WebOperationContext.Current.IncomingRequest.UriTemplateMatch.QueryParameters["format"];
            SyndicationFeedFormatter formatter = null;
            if (query == "atom")
            {
                formatter = new Atom10FeedFormatter(feed);
            }
            else
            {
                formatter = new Rss20FeedFormatter(feed);
            }

            return formatter;
        }

        public SyndicationFeedFormatter CSharp_HowDoI()
        {
            // Create a new Syndication Feed.
            SyndicationFeed feed = new SyndicationFeed("C# Articles - How Do I?", "A WCF Syndication Feed for C# Articles - How Do I?", null);
            List<SyndicationItem> items = new List<SyndicationItem>();

            // Create a new Syndication Item.
            SyndicationItem item = new SyndicationItem("An item for C# Articles - How Do I?", "Item content C# Articles - How Do I?", null);
            items.Add(item);
            feed.Items = items;

            // Return ATOM or RSS based on query string
            // rss -> http://localhost:8732/Design_Time_Addresses/PBDesk.FeedService/Feed1/
            // atom -> http://localhost:8732/Design_Time_Addresses/PBDesk.FeedService/Feed1/?format=atom
            string query = WebOperationContext.Current.IncomingRequest.UriTemplateMatch.QueryParameters["format"];
            SyndicationFeedFormatter formatter = null;
            if (query == "atom")
            {
                formatter = new Atom10FeedFormatter(feed);
            }
            else
            {
                formatter = new Rss20FeedFormatter(feed);
            }

            return formatter;
        }


        public SyndicationFeedFormatter VisualStudioNews()
        {

            SyndicationFeed feed = new SyndicationFeed("VisualStudio", "A WCF Syndication Feed for VisualStudio ", null);
            List<SyndicationItem> items = new List<SyndicationItem>();


            SyndicationItem item = new SyndicationItem("An item for VisualStudio", "Item content VisualStudio", null);
            items.Add(item);
            feed.Items = items;

            return new Rss20FeedFormatter(feed);

           
        }

        public SyndicationFeedFormatter AspNetNews()
        {
            SyndicationFeed feed = new SyndicationFeed("ASP.net", "A WCF Syndication Feed for ASP.net", null);
            List<SyndicationItem> items = new List<SyndicationItem>();


            SyndicationItem item = new SyndicationItem("An item for ASP.net", "Item content ASP.net", null);
            items.Add(item);
            feed.Items = items;

            return new Rss20FeedFormatter(feed);
        }

        public SyndicationFeedFormatter VBNews()
        {
            SyndicationFeed feed = new SyndicationFeed("VBArticles - How Do I?", "A WCF Syndication Feed for VB Articles - How Do I?", null);
            List<SyndicationItem> items = new List<SyndicationItem>();


            SyndicationItem item = new SyndicationItem("An item for VB Articles - How Do I?", "Item content VB Articles - How Do I?", null);
            items.Add(item);
            feed.Items = items;

            return new Rss20FeedFormatter(feed);
        }

        public SyndicationFeedFormatter DotNetNews()
        {
            SyndicationFeed feed = new SyndicationFeed(".Net Articles - How Do I?", "A WCF Syndication Feed for .Net Articles - How Do I?", null);
            List<SyndicationItem> items = new List<SyndicationItem>();


            SyndicationItem item = new SyndicationItem("An item for .net Articles - How Do I?", "Item content .Net Articles - How Do I?", null);
            items.Add(item);
            feed.Items = items;

            return new Rss20FeedFormatter(feed);
        }

        public SyndicationFeedFormatter UmbracoNews()
        {
            SyndicationFeed feed = new SyndicationFeed("Umbaco", "A WCF Syndication Feed for Umbaco", null);
            List<SyndicationItem> items = new List<SyndicationItem>();


            SyndicationItem item = new SyndicationItem("An item for Umbaco", "Item content Umbaco", null);
            items.Add(item);
            feed.Items = items;

            return new Rss20FeedFormatter(feed);
        }
    }
}
